package com.ywxx.dyhelper.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;

import com.ywxx.dyhelper.BuildConfig;
import com.ywxx.dyhelper.R;
import com.ywxx.dyhelper.base.BaseAcitivity;
import com.ywxx.dyhelper.model.TaskConfig;
import com.ywxx.dyhelper.utils.ConstValues;
import com.ywxx.dyhelper.widget.NumberAddSubView;

/**
 * 一键取关
 */
public class CancelFollowActivity extends BaseAcitivity
{

    private NumberAddSubView labOperNum;
    private Switch sw_follow;
    private Switch sw_like;
    private TextView labinfo;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cancel_follow);
        InitUI();
        DataToUI();

    }

    @Override
    protected void InitUI()
    {
        InitTitle();
        labOperNum = findViewById(R.id.labOperNum);
        sw_follow = findViewById(R.id.sw_follow);
        sw_like = findViewById(R.id.sw_like);
        labinfo = findViewById(R.id.labinfo);

        labOperNum.setValue(200);
        labOperNum.setMaxValue(5000);
        labOperNum.setSeekNum(50);

        if (TaskType > 4)
        {
            findViewById(R.id.ll_follow).setVisibility(View.GONE);
            findViewById(R.id.ll_like).setVisibility(View.GONE);

            labinfo.setText(TaskType == 5 ? "关注粉丝数量" : "回关粉丝数量");
        }


        llStart.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                appconfig = new TaskConfig();
                appconfig.runtime = labOperNum.getValue();
                appconfig.auto_follow = sw_follow.isChecked();
                appconfig.auto_like = sw_like.isChecked();
                appconfig.unit = "条";

                ConstValues.SaveValue(CancelFollowActivity.this, "runtime" + TaskType, appconfig.runtime);
                ConstValues.SaveValue(CancelFollowActivity.this, "follow" + TaskType, appconfig.auto_follow);
                ConstValues.SaveValue(CancelFollowActivity.this, "like" + TaskType, appconfig.auto_like);

                StartTaskServer(TaskType);
            }
        });
    }

    @Override
    protected void DataToUI()
    {
        int num = ConstValues.getIntValue(this, "runtime" + TaskType, BuildConfig.DEBUG ? 30 : 100);
        boolean follow = ConstValues.getBooleanValue(this, "follow" + TaskType, true);
        boolean like = ConstValues.getBooleanValue(this, "like" + TaskType, false);
        labOperNum.setValue(num);
        sw_follow.setChecked(follow);
        sw_like.setChecked(like);

    }
}